﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.Model;
using BDCS.BLL;

namespace BDCS.UI
{
    public partial class AlterBuildDesignDcriterionTypes : Form
    {
        #region 成员字段
        private Model.T_BuildDesignDcriterionTypes modelBuildDesignDcriterionType;
        private BLL.T_BuildDesignDcriterionTypes bllBuildDesignDcriterionType;
        private int dtid;
        private string dtName;
        private string dtNameTwo;
        private string dtDescribe;
        private string dtDescribeTwo; 
        #endregion
        #region 构造函数
        public AlterBuildDesignDcriterionTypes()
        {
            InitializeComponent();
        }
        public AlterBuildDesignDcriterionTypes(Model.T_BuildDesignDcriterionTypes buildDesignDcriterionType)
        {
            this.modelBuildDesignDcriterionType = buildDesignDcriterionType;
            InitializeComponent();
        } 
        #endregion
        #region 成员事件
        private void AlterBuildDesignDcriterionTypes_Load(object sender, EventArgs e)
        {
            this.dtid = this.modelBuildDesignDcriterionType.DTID;
            this.txtBuildDesignDcriterionTypeName.Text = this.modelBuildDesignDcriterionType.DTName;
            this.txtBuildDesignDcriterionTypeDescribe.Text = this.modelBuildDesignDcriterionType.DTDescirbe;
            this.dtName = this.modelBuildDesignDcriterionType.DTName;
            this.dtDescribe = this.modelBuildDesignDcriterionType.DTDescirbe;
            this.dtNameTwo = this.modelBuildDesignDcriterionType.DTName;
            this.dtDescribeTwo = this.modelBuildDesignDcriterionType.DTDescirbe;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtBuildDesignDcriterionTypeName.Text.Trim() != dtName || txtBuildDesignDcriterionTypeDescribe.Text.Trim() != dtDescribe)
            {
                try
                {
                    bllBuildDesignDcriterionType = new BLL.T_BuildDesignDcriterionTypes();
                    modelBuildDesignDcriterionType = new Model.T_BuildDesignDcriterionTypes();
                    modelBuildDesignDcriterionType.DTID = this.dtid;
                    modelBuildDesignDcriterionType.DTName = txtBuildDesignDcriterionTypeName.Text.Trim();
                    modelBuildDesignDcriterionType.DTDescirbe = txtBuildDesignDcriterionTypeDescribe.Text.Trim();
                    if (bllBuildDesignDcriterionType.Update(modelBuildDesignDcriterionType) == true)
                    {
                        dtName = txtBuildDesignDcriterionTypeName.Text.Trim();
                        dtDescribe = txtBuildDesignDcriterionTypeDescribe.Text.Trim();
                        BDCS.Common.TreeViewState.IsChangedDcriterion = true;
                        MessageBox.Show("修改成功！");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            else
            {
                MessageBox.Show("没有修改任何内容，不需要提交！");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            txtBuildDesignDcriterionTypeName.Text = dtNameTwo;
            txtBuildDesignDcriterionTypeDescribe.Text = dtDescribeTwo;
            if (this.dtName != dtNameTwo && dtDescribe != dtDescribeTwo)
            {
                modelBuildDesignDcriterionType = new Model.T_BuildDesignDcriterionTypes();
                modelBuildDesignDcriterionType.DTID = this.dtid;
                modelBuildDesignDcriterionType.DTName = dtNameTwo;
                modelBuildDesignDcriterionType.DTDescirbe = dtDescribeTwo;
                bllBuildDesignDcriterionType = new BLL.T_BuildDesignDcriterionTypes();
                try
                {
                    bllBuildDesignDcriterionType.Update(modelBuildDesignDcriterionType);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        } 
        #endregion
    }
}
